namespace Angelus.Oracle.Entity.OracleClient
{
    using System;
    using System.Data.Common;
    using System.Security;
    using System.Security.Permissions;
    using global::Oracle.DataAccess.Client;
    using OracleGen;

    /// <summary>
    /// Description of DbOracleFactory.
    /// </summary>
    public class DbOracleFactory : DbProviderFactory, IServiceProvider
    {
        #region Fields

        public static readonly DbOracleFactory Instance = new DbOracleFactory();

        #endregion

        #region Factory Overrides

        /// <summary>
        /// 
        /// </summary>
        public override bool CanCreateDataSourceEnumerator
        {
            get { return true; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override DbCommand CreateCommand()
        {
            return new DbOracleCommand();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override DbCommandBuilder CreateCommandBuilder()
        {
            return new OracleCommandBuilder();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override DbConnection CreateConnection()
        {
            return new DbOracleConnection();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override DbConnectionStringBuilder CreateConnectionStringBuilder()
        {
            return new OracleConnectionStringBuilder();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override DbDataAdapter CreateDataAdapter()
        {
            return new OracleDataAdapter();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override DbParameter CreateParameter()
        {
            return new OracleParameter();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        public override CodeAccessPermission CreatePermission(PermissionState state)
        {
            throw new NotSupportedException();
        }

        #endregion

        #region IServiceProvider Implementation

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        object IServiceProvider.GetService(Type serviceType)
        {
            if (serviceType == typeof (DbProviderServices))
            {
                return OracleEntityProviderServices.Instance;
            }

            return null;
        }

        #endregion
    }
}